package com.xinkao.log.config.system;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 周洋
 * @Description
 * @createTime 2021/9/26 16:40
 */
@Configuration
public class TopicMqConfig {
    /**
     * 配置操作日志队列
     */
    public final static String OPERATE_LOG_QUEUE_NAME = "operate.log.queue";

    /**
     * 路由的交换机
     */
    public final static String TOPIC_EXCHANGE_NAME = "log.topic.exchange";

    /**
     * 配置操作日志TOPIC，#可以匹配多个
     */
    public final static String OPERATE_LOG_TOPIC  = "topic.operateLog.#";

    /**
     * @Title: topicExchange
     * @Description: 配置 TopicExchange Topic类型的交换机
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(TOPIC_EXCHANGE_NAME);
    }

    /**
     * @Title: operateLogQueue
     * @Description: 配置 operateLogQueue 操作日志队列
     */
    @Bean
    public Queue operateLogQueue() {
        return new Queue(OPERATE_LOG_QUEUE_NAME);
    }

    /**
     * @Title: operateLogBinding
     * @Description: 将操作日志队列绑定到TOPIC_EXCHANGE_NAME交换机，并且匹配规则为匹配多个
     */
    @Bean
    public Binding operateLogBinding() {
        return BindingBuilder.bind(operateLogQueue()).to(topicExchange()).with(OPERATE_LOG_TOPIC);
    }

}
